linux 服务器批量配置ntp时间同步

前言

搭建思路:首先取一台做为时间服务端即ntpd,其余的服务器作为客户端做时间同步

环境

服务端:192.168.0.100

操作系统:centos7.6

其它:ansible 2.9.23 ntp-4.2.6p5-29 ntpdate-4.2.6p5-29

操作步骤

1、服务端

安装ntpd服务,使用yum install ntp -y

修改配置

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1 
restrict ::1
#允许同步时间的ip段
restrict 192.0.0.0 mask 255.255.255.0 nomodify notrap
# 时间服务器,根据实际情况配置
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

#在没有互联网的情况下,使用以下配置,将本机时间作为时间源
#server 127.127.1.0 
#fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw
 
keys /etc/ntp/keys

disable monitor

启动服务

systemctl start ntpd

查看ntpd服务状态

ntpq -p

确认状态正常的情况下,在往下配置其余客户端服务器

2、客户端

  使用ansible进行批量配置

ansible all -m shell -a "(echo '*/59 * * * * /usr/sbin/ntpdate 192.168.0.100 >> /var/log/ntpdate.log' ; crontab -l ) | crontab"

注:使用crontab定时时间同步

以上就是配置的步骤,有疑问欢迎留言!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hu_wenjie

您的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值